/**
 * @file wa_disp_drv.c
 * 
 */

/*********************
 *      INCLUDES
 *********************/
#include "wa_disp_drv.h"
/*********************
 *      DEFINES
 *********************/

/**********************
 *      TYPEDEFS
 **********************/

/**********************
 *  STATIC PROTOTYPES
 **********************/

/**********************
 *  STATIC VARIABLES
 **********************/
static wa_disp_drv disp_drv;
/**********************
 *      MACROS
 **********************/

/**********************
 *   GLOBAL FUNCTIONS
 **********************/

/**
 * init the display driver
 * @return wa_nok:display driver is not valid，wa_ok:display driver is valid
 */
 
wa_result wa_disp_drv_init(void)
{
	if(disp_drv.disp_setpixel==NULL)
	{
		return wa_nok;
	}
	if (disp_drv.disp_getpixel == NULL)
	{
		return wa_nok;
	}
	if(disp_drv.disp_fill==NULL)
	{
		return wa_nok;
	}
	if(disp_drv.disp_clear ==NULL)
	{
		return wa_nok;
	}
	if (disp_drv.disp_update == NULL)
	{
		return wa_nok;
	}
	return wa_ok;
}

/**
 *set setpixel function
 * @param setpixel function in driver
 */
void wa_disp_drv_set_setpixel(void (*disp_setpixel)(int32_t, int32_t, wa_gui_color))
{
	disp_drv.disp_setpixel=disp_setpixel;
}

/**
 *set getpixel function
 * @param getpixel function in driver
 */
void wa_disp_drv_set_getpixel(wa_gui_color(*disp_getpixel)(int32_t, int32_t))
{
	disp_drv.disp_getpixel = disp_getpixel;
}


/**
 *set fill function
 * @param fill function in driver
 */
void wa_disp_drv_set_fill(void (*disp_fill)(int32_t,int32_t,int32_t,int32_t,wa_gui_color))
{
	disp_drv.disp_fill=disp_fill;
}
 
 
 /**
 *set clear function
 * @param clear function in driver
 */ 
void wa_disp_drv_set_clear(void (*disp_clear)(void))
{
	disp_drv.disp_clear = disp_clear;
}

/**
 *set update function
 * @param update function in driver
 */
void wa_disp_drv_set_update(void (*disp_update)(int32_t, int32_t, int32_t, int32_t))
{
	disp_drv.disp_update = disp_update;
}

/**
 * display a point
 * @param x point x
 * @param y point y
 * @param color point color
 */
void wa_disp_drv_setpixel(int32_t x, int32_t y, wa_gui_color color)
{
	if(disp_drv.disp_setpixel!=NULL)
	{
		disp_drv.disp_setpixel(x,y,color);
	}
}

/**
 * get a point
 * @param x point x
 * @param y point y
 * @return color point color
 */
wa_gui_color wa_disp_drv_getpixel(int32_t x, int32_t y)
{
	if (disp_drv.disp_getpixel != NULL)
	{
		return disp_drv.disp_getpixel(x, y);
	}
	return WA_COLOR_BACKGROUND;
}

/**
 * display fill a rect
 * @param x start point x
 * @param y start point y
 * @param width rect width
 * @param heighy rect height
 * @param color point color
 */
void wa_disp_drv_fill(int32_t x, int32_t y, int32_t width, int32_t height, wa_gui_color color)
{
	if(disp_drv.disp_fill!=NULL)
	{
		disp_drv.disp_fill(x,y,width,height,color);
	}
}

/**
 * display clear
 */
void wa_disp_drv_clear(void)
{
	if(disp_drv.disp_clear !=NULL)
	{
		disp_drv.disp_clear();
	}
}
 
/**
 * display update a area
 * @param x start point x
 * @param y start point y
 * @param width rect width
 * @param heighy rect height
 */
void wa_disp_drv_update(int32_t x, int32_t y, int32_t width, int32_t height)
{
	if (disp_drv.disp_update != NULL)
	{
		disp_drv.disp_update(x, y, width, height);
	}
}

/**********************
 *   STATIC FUNCTIONS
 **********************/
